export const secretPdf = {
  // 渲染阅读器，参数options
  render: function (options) {
    var options = options || {}
    // 获取参数传入的pdf插件使用html节点
    var elementPdfWrap = document.getElementById(options.needNodeId)
    if (!options.needNodeId || !options.needPublicKey || !options.needPdfApi || !options.needPath) {
      alert('缺少必须参数，请检查！')
      return
    }

    // 创建节点，存储数据，用于保存参数，提供给iframe内调用
    var paraStorage = document.createElement('div')
    paraStorage.style.display = 'none'
    // 创建input存储节点
    // 接口api存储
    var paraApiStorage = document.createElement('input')
    paraApiStorage.value = options.needPdfApi
    paraApiStorage.setAttribute('id', 'secret-storage-api')
    // 公钥存储
    var paraPublickeyStorage = document.createElement('input')
    paraPublickeyStorage.value = options.needPublicKey
    paraPublickeyStorage.setAttribute('id', 'secret-storage-publickey')
    // 试读页数存储
    var paraReadPageStorage = document.createElement('input')
    paraReadPageStorage.value = options.limitPage
    paraReadPageStorage.setAttribute('id', 'secret-pdf-limit-page')
    // 默认双页还是单页显示
    var paraPageModeStorage = document.createElement('input')
    paraPageModeStorage.value = options.pageMode || 'ODD'
    paraPageModeStorage.setAttribute('id', 'secret-pdf-page-mode')
    // 设置页面大小
    var paraPageZoomStorage = document.createElement('input')
    paraPageZoomStorage.value = options.pageZoom
    paraPageZoomStorage.setAttribute('id', 'secret-pdf-page-zoom')
    // 添加节点到页面
    paraStorage.appendChild(paraApiStorage)
    paraStorage.appendChild(paraPublickeyStorage)
    paraStorage.appendChild(paraReadPageStorage)
    paraStorage.appendChild(paraPageModeStorage)
    paraStorage.appendChild(paraPageZoomStorage)
    elementPdfWrap.appendChild(paraStorage)
    // 创建iframe节点，用来展示pdf
    var pdfIframeWrap = document.createElement('div')
    pdfIframeWrap.style.width = '100%'
    pdfIframeWrap.style.height = '100%'
    var pdfIframeElement = document.createElement('iframe')
    pdfIframeElement.style.border = 'none'
    pdfIframeElement.style.width = '100%'
    pdfIframeElement.style.height = '100%'
    pdfIframeElement.src = options.needPath + 'web/viewer.html'
    pdfIframeWrap.appendChild(pdfIframeElement)
    elementPdfWrap.appendChild(pdfIframeWrap)
  }
}
